import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Deque;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static String myPrint(double n, int t1) {
        String s = "%." + String.valueOf(t1) + "f";
        return String.format(s, n);
    }

    public static String myPrint(double n, int t1, int t2) {
        String s = "%" + String.valueOf(t1) + "." + String.valueOf(t2) + "f";
        return String.format(s, n);
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] nums = new int[n];
        boolean[] isVisited = new boolean[n];
        int count = n;//当前还剩n个元素没被删除
        int index = 0;
        int flag = 1;
        while(count > 1){
            if(flag % 3 == 0){
                isVisited[index] = true;
                count--;
            }
            index++;
            index %= n;
            while(count != 0 && isVisited[index]){
                index++;
                index %= n;
            }
            flag++;
        }
        System.out.println(index+1);
    }
}